﻿using System;
using VideoServices.Domain.DAL;
using VideoServices.Domain.Entities;
using VideoServices.Common.Enum;
using System.Collections.Generic;

namespace VideoServices.Business
{
    public class OrderBusinessObject
    {
        #region Fields

        private readonly IOrderDataAccess orderDao;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderBusinessObject"/> class.
        /// </summary>
        public OrderBusinessObject()
        {
            orderDao = new OrderDataAccess();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderBusinessObject"/> class.
        /// </summary>
        /// <param name="dao">The DAO.</param>
        public OrderBusinessObject(IOrderDataAccess dao)
        {
            // This constructor enables easy TDD as it takes in whatever IOrderDataAccess implementation.
            orderDao = dao;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the order by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Order GetOrderById(Guid id)
        {
            Order order;
            try
            {
                order = orderDao.GetOrderById(id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return order;
        }

        /// <summary>
        /// Creates the order.
        /// </summary>
        /// <param name="newOrder">The new order.</param>
        /// <returns></returns>
        public Order CreateOrder(Order newOrder)
        {
            Order order;
            try
            {
                order = orderDao.CreateOrder(newOrder);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return order;
        }

        #endregion
    }
}
